/* Includes ------------------------------------------------------------------*/
#include "at32f403a_407_wk_config.h"

/* private includes ----------------------------------------------------------*/
/* add user code begin private includes */
#include "at32f403a_407_board.h"
/* add user code end private includes */
#include "universal.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "cmsis_armcc.h"

void get_compile_datetime(char * strdate, char * strtime)
{
    char s_month[5];
    int month, day, year;
    const char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
    sscanf(__DATE__, "%s %d %d", s_month, &day, &year);

    month = (strstr(month_names, s_month) - month_names) / 3 + 1;
    

    if (strdate != NULL)
    {
        sprintf(strdate, "%04d-%02d-%02d", year, month, day);
    }    
    if (strtime != NULL)
    {
        sprintf(strtime, "%s", __TIME__);
    }
}

unsigned int calc_file_sum(unsigned char * data, int len)
{
    unsigned int sum = 0;
    int i;
    for (i = 0; i < len; ++i)
    {
        sum += data[i];
    }
    return sum;
}
void SoftReset(void)
{     
     vTaskDelay( pdMS_TO_TICKS( 2000 ));
    __set_FAULTMASK(1); 
    NVIC_SystemReset(); 
}

void get_chip_serial_num(uint32_t*cpuid)
{
    cpuid[0] = *(__IO uint32_t *)(0x1FFF7A10);
    cpuid[1] = *(__IO uint32_t *)(0x1FFF7A14);
    cpuid[2] = *(__IO uint32_t *)(0x1FFF7A18);
}